from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-24 14:02:28.593208
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 24, Jun, 2022
Time: 14:02:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5845
Nobs: 697.000 HQIC: -49.9446
Log likelihood: 8673.81 FPE: 1.62458e-22
AIC: -50.1716 Det(Omega_mle): 1.42910e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296891 0.057975 5.121 0.000
L1.Burgenland 0.108089 0.038023 2.843 0.004
L1.Kärnten -0.109543 0.020121 -5.444 0.000
L1.Niederösterreich 0.213753 0.079371 2.693 0.007
L1.Oberösterreich 0.104217 0.077964 1.337 0.181
L1.Salzburg 0.256602 0.040694 6.306 0.000
L1.Steiermark 0.046379 0.052981 0.875 0.381
L1.Tirol 0.109434 0.042991 2.546 0.011
L1.Vorarlberg -0.058446 0.037310 -1.566 0.117
L1.Wien 0.037984 0.068971 0.551 0.582
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048551 0.121719 0.399 0.690
L1.Burgenland -0.033994 0.079829 -0.426 0.670
L1.Kärnten 0.041209 0.042243 0.976 0.329
L1.Niederösterreich -0.169335 0.166641 -1.016 0.310
L1.Oberösterreich 0.426752 0.163685 2.607 0.009
L1.Salzburg 0.288907 0.085436 3.382 0.001
L1.Steiermark 0.101663 0.111233 0.914 0.361
L1.Tirol 0.318419 0.090259 3.528 0.000
L1.Vorarlberg 0.028398 0.078333 0.363 0.717
L1.Wien -0.043168 0.144806 -0.298 0.766
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185346 0.029701 6.240 0.000
L1.Burgenland 0.090776 0.019479 4.660 0.000
L1.Kärnten -0.007989 0.010308 -0.775 0.438
L1.Niederösterreich 0.265185 0.040662 6.522 0.000
L1.Oberösterreich 0.137354 0.039941 3.439 0.001
L1.Salzburg 0.045472 0.020848 2.181 0.029
L1.Steiermark 0.021038 0.027142 0.775 0.438
L1.Tirol 0.091481 0.022024 4.154 0.000
L1.Vorarlberg 0.057021 0.019114 2.983 0.003
L1.Wien 0.115633 0.035334 3.273 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110692 0.030146 3.672 0.000
L1.Burgenland 0.045392 0.019771 2.296 0.022
L1.Kärnten -0.013756 0.010462 -1.315 0.189
L1.Niederösterreich 0.190104 0.041271 4.606 0.000
L1.Oberösterreich 0.304978 0.040539 7.523 0.000
L1.Salzburg 0.106974 0.021159 5.056 0.000
L1.Steiermark 0.105198 0.027548 3.819 0.000
L1.Tirol 0.103107 0.022354 4.612 0.000
L1.Vorarlberg 0.068391 0.019400 3.525 0.000
L1.Wien -0.021866 0.035863 -0.610 0.542
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131601 0.055108 2.388 0.017
L1.Burgenland -0.050443 0.036142 -1.396 0.163
L1.Kärnten -0.044577 0.019125 -2.331 0.020
L1.Niederösterreich 0.153667 0.075445 2.037 0.042
L1.Oberösterreich 0.141675 0.074107 1.912 0.056
L1.Salzburg 0.284915 0.038681 7.366 0.000
L1.Steiermark 0.050878 0.050360 1.010 0.312
L1.Tirol 0.167099 0.040864 4.089 0.000
L1.Vorarlberg 0.094264 0.035465 2.658 0.008
L1.Wien 0.073401 0.065560 1.120 0.263
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053542 0.043846 1.221 0.222
L1.Burgenland 0.037606 0.028757 1.308 0.191
L1.Kärnten 0.051069 0.015217 3.356 0.001
L1.Niederösterreich 0.217413 0.060028 3.622 0.000
L1.Oberösterreich 0.294619 0.058963 4.997 0.000
L1.Salzburg 0.047080 0.030776 1.530 0.126
L1.Steiermark 0.002410 0.040069 0.060 0.952
L1.Tirol 0.140575 0.032514 4.324 0.000
L1.Vorarlberg 0.074147 0.028218 2.628 0.009
L1.Wien 0.082445 0.052163 1.581 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172317 0.052398 3.289 0.001
L1.Burgenland -0.001761 0.034365 -0.051 0.959
L1.Kärnten -0.063331 0.018185 -3.483 0.000
L1.Niederösterreich -0.080808 0.071736 -1.126 0.260
L1.Oberösterreich 0.195517 0.070464 2.775 0.006
L1.Salzburg 0.056101 0.036779 1.525 0.127
L1.Steiermark 0.238229 0.047884 4.975 0.000
L1.Tirol 0.497691 0.038855 12.809 0.000
L1.Vorarlberg 0.044986 0.033721 1.334 0.182
L1.Wien -0.056323 0.062337 -0.904 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164612 0.059545 2.764 0.006
L1.Burgenland -0.011999 0.039053 -0.307 0.759
L1.Kärnten 0.063714 0.020666 3.083 0.002
L1.Niederösterreich 0.202382 0.081521 2.483 0.013
L1.Oberösterreich -0.072579 0.080075 -0.906 0.365
L1.Salzburg 0.210659 0.041795 5.040 0.000
L1.Steiermark 0.129295 0.054415 2.376 0.017
L1.Tirol 0.065720 0.044155 1.488 0.137
L1.Vorarlberg 0.119464 0.038320 3.117 0.002
L1.Wien 0.131304 0.070839 1.854 0.064
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.365353 0.034486 10.594 0.000
L1.Burgenland 0.006628 0.022618 0.293 0.769
L1.Kärnten -0.023357 0.011969 -1.951 0.051
L1.Niederösterreich 0.218130 0.047214 4.620 0.000
L1.Oberösterreich 0.203051 0.046376 4.378 0.000
L1.Salzburg 0.043921 0.024206 1.814 0.070
L1.Steiermark -0.016258 0.031515 -0.516 0.606
L1.Tirol 0.105742 0.025573 4.135 0.000
L1.Vorarlberg 0.069290 0.022194 3.122 0.002
L1.Wien 0.029714 0.041027 0.724 0.469
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037442 0.135117 0.193196 0.153974 0.113990 0.100335 0.056980 0.217922
Kärnten 0.037442 1.000000 -0.015632 0.133785 0.055483 0.095254 0.436068 -0.053901 0.093826
Niederösterreich 0.135117 -0.015632 1.000000 0.335556 0.142059 0.293377 0.089866 0.174930 0.312493
Oberösterreich 0.193196 0.133785 0.335556 1.000000 0.227552 0.324751 0.175391 0.161917 0.265535
Salzburg 0.153974 0.055483 0.142059 0.227552 1.000000 0.137843 0.114847 0.138457 0.133325
Steiermark 0.113990 0.095254 0.293377 0.324751 0.137843 1.000000 0.144758 0.128453 0.073411
Tirol 0.100335 0.436068 0.089866 0.175391 0.114847 0.144758 1.000000 0.110655 0.143444
Vorarlberg 0.056980 -0.053901 0.174930 0.161917 0.138457 0.128453 0.110655 1.000000 0.006158
Wien 0.217922 0.093826 0.312493 0.265535 0.133325 0.073411 0.143444 0.006158 1.000000